<?php
namespace Admin\Controller;
use Think\Controller;
class AnswerController extends CommonController {

    //显示答案列表
    public function AnswerList(){
        $answer=M('user');
        $this -> AnswerList = $answer
            ->join('question on question.q_id=user.an_q_id')
            ->join('user on user.u_id=user.an_u_id')->select();
        //显示编号
        $cnt = 1;
        $this -> assign('cnt',$cnt);
        $this -> display();
    }

    //显示答案详情
    public function AnswerInfo($an_id){

       //$this -> display();
        $answer=M('user');

        $this -> AnswerInfo = $answer
            ->join('question on question.q_id=user.an_q_id')
            ->join('user on user.u_id=user.an_u_id')->select($an_id);

        //dump($this -> QuestionInfo);

        $this -> display();

    }


    //删除回答
    public function AnswerDel($an_id){

        $Answer = M('user');

        $photoName = ($Answer->select($an_id))['0']['an_pic'];

        if ($photoName != 'default.png') { //如果不是默认文件
            unlink('./Public/upload/answerpics/' . $photoName); //删除对应文件
        }
        if ($Answer->delete($an_id)) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }

    //删除回答
    public function AnswerInfoDel($an_id){

        $Answer = M('user');

        $photoName = ($Answer->select($an_id))['0']['an_pic'];

        if ($photoName != 'default.png') { //如果不是默认文件
            unlink('./Public/upload/answerpics/' . $photoName); //删除对应文件
        }
        if ($Answer->delete($an_id)) {
            $this->success('删除成功','/zxdyxt_php/Admin/Answer/AnswerList', 3);
        } else {
            $this->error('删除失败');
        }
    }








}